package com.poly.flowable.listener;

import com.poly.common.core.domain.R;
import com.poly.common.core.tools.utils.Func;
import com.poly.common.core.utils.listener.BaseListener;
import com.poly.system.RemoteUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Optional;
import java.util.stream.Collectors;
import java.util.stream.Stream;

@Component
public class UserListener implements BaseListener<Object, String> {


    @Resource
    private RemoteUserService remoteUserService;
    @Override
    public String handle(Object parameter) {
        if (Func.isNotEmpty(parameter)) {
            String[] userIds = Func.toStrArray(parameter.toString());
            return R.getData(remoteUserService.getCacheUserName(Stream.of(userIds).map(Long::parseLong)
                    .collect(Collectors.toList())));
        }
        return "";
    }
}
